<?php
declare(strict_types=1);
namespace App\WebSocket\Chat;

use App\Model\Dao\Specific\IServerUser;
use Psr\Http\Message\RequestInterface;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\WebSocket\Server\Annotation\Mapping\MessageMapping;
use Swoft\WebSocket\Server\Annotation\Mapping\WsController;
use Swoft\WebSocket\Server\Message\Request;
use Swoft\WebSocket\Server\Message\Response;
use Tool\AjaxReturn;

/**
 * Class LoginController
 * @WsController(prefix="login")
 * @package App\Http\Controller
 */
class LoginController
{
    /**
     * @Inject()
     * @var IServerUser
     */
    private $iserverUserData;

    /**
     * @MessageMapping(command="handle")
     * @param RequestInterface $request
     * @return array
     */
    public function handle(Request $request, Response $response): array
    {
        $data = $request->getMessage()->getData();

        $receive = $this->iserverUserData->checkUser($data);


//        vdump($request->getFrame());
        return AjaxReturn::dispatcher(['code' => $receive], '成功');
    }
}